package personal.controller.util;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 *
 * @author LocNguyen
 */
public class HandlerUtil {
    public static void writeResponse(String jsonData, ServletRequest req, ServletResponse res) {

        PrintWriter printer;
        try {
            printer = res.getWriter();
            res.setContentType("application/x-javascript; charset=utf-8");
            String callback = req.getParameter("jsoncallback");
            if (callback != null) {
                printer.write(callback + "(");
            }
            printer.write(jsonData);
            if (callback != null) {
                printer.write(")");
            }
            printer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
}
